import api from "@/api/apiServer";
import { filterDate } from "@/unit/tool";
let processingOption = [];
let pickingOption = [];
async function getProcessingOption(parentCode) {
  let res = await api.DictFindByCode({ parentCode });
  processingOption = res.data;
}
async function getPickingOption(parentCode) {
  let res = await api.DictFindByCode({ parentCode });
  pickingOption = res.data;
}
getProcessingOption("dict.processing", processingOption);
getPickingOption("dict.picking", pickingOption);

// 格式化数据来源
function caseSource(value, option) {
  let result = option.filter((item) => {
    return item.id === value;
  });

  if (result.length > 0) {
    return result[0].dictName;
  } else {
    return "";
  }
}
const column = [
  {
    title: "商品编号",
    dataIndex: "goodsCode",
    key: "goodsCode",
    align: "center",
  },
  {
    title: "商品名称",
    dataIndex: "goodsName",
    key: "goodsName",
    align: "center",
  },
  {
    title: "商品规格",
    dataIndex: "specifications",
    key: "specifications",
    align: "center",
  },
  {
    title: "数量",
    dataIndex: "amount",
    key: "amount",
    align: "center",
  },
];

const columns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "加工单号",
    dataIndex: "processNum",
    key: "processNum",
    align: "center",
  },

  {
    title: "生产计划",
    dataIndex: "planNum",
    key: "planNum",
    align: "center",
  },
  {
    title: "加工单数量",
    dataIndex: "productionQuantity",
    key: "productionQuantity",
    align: "center",
  },
  {
    title: "班次",
    dataIndex: "workTeamName",
    key: "workTeamName",
    align: "center",
  },
  {
    title: "备料",
    dataIndex: "pickStatus",
    key: "pickStatus",
    align: "center",
    customRender: (text, record, index) => {
      return caseSource(text, pickingOption);
    },
  },
  {
    title: "状态",
    dataIndex: "status",
    key: "status",
    align: "center",
    customRender: (text, record, index) => {
      return caseSource(text, processingOption);
    },
  },
  {
    title: "开始时间",
    dataIndex: "processStartTime",
    key: "processStartTime",
    align: "center",
    customRender: (text, record, index) => {
      return filterDate(text);
    },
  },
  {
    title: "结束时间",
    dataIndex: "processEndTime",
    key: "processEndTime",
    align: "center",
    customRender: (text, record, index) => {
      return filterDate(text);
    },
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
  },
];

export { column, columns };
